home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Bank smakow / BankSmakow.air / BankSmakow.swf / scripts / air / update / states / HSM.as next >
Text File  |  2009-12-16  |  2KB  |  86 lines

  1. package air.update.states
  2. {
  3.    import flash.errors.IllegalOperationError;
  4.    import flash.events.ErrorEvent;
  5.    import flash.events.Event;
  6.    import flash.events.EventDispatcher;
  7.    import flash.events.TimerEvent;
  8.    import flash.utils.Timer;
  9.    
  10.    public class HSM extends EventDispatcher
  11.    {
  12.        
  13.       
  14.       private var asyncTimer:Timer;
  15.       
  16.       private var _hsmState:Function;
  17.       
  18.       public function HSM(param1:Function)
  19.       {
  20.          super();
  21.          _hsmState = param1;
  22.       }
  23.       
  24.       public function init() : void
  25.       {
  26.          try
  27.          {
  28.             _hsmState(new HSMEvent(HSMEvent.ENTER));
  29.          }
  30.          catch(e:Error)
  31.          {
  32.             _hsmState(new ErrorEvent(ErrorEvent.ERROR,false,false,e.message,e.errorID));
  33.          }
  34.       }
  35.       
  36.       protected function get stateHSM() : Function
  37.       {
  38.          return _hsmState;
  39.       }
  40.       
  41.       protected function transition(param1:Function) : void
  42.       {
  43.          var state:Function = param1;
  44.          asyncTimer = null;
  45.          try
  46.          {
  47.             _hsmState(new HSMEvent(HSMEvent.EXIT));
  48.             _hsmState = state;
  49.             _hsmState(new HSMEvent(HSMEvent.ENTER));
  50.          }
  51.          catch(e:Error)
  52.          {
  53.             _hsmState(new ErrorEvent(ErrorEvent.ERROR,false,false,"Unhandled exception " + e.name + ": " + e.message,e.errorID));
  54.          }
  55.       }
  56.       
  57.       protected function transitionAsync(param1:Function) : void
  58.       {
  59.          var state:Function = param1;
  60.          if(asyncTimer)
  61.          {
  62.             throw new IllegalOperationError("async transition already queued");
  63.          }
  64.          asyncTimer = new Timer(0,1);
  65.          asyncTimer.addEventListener(TimerEvent.TIMER,function(param1:Event):void
  66.          {
  67.             transition(state);
  68.          });
  69.          asyncTimer.start();
  70.       }
  71.       
  72.       public function dispatch(param1:Event) : void
  73.       {
  74.          var event:Event = param1;
  75.          try
  76.          {
  77.             _hsmState(event);
  78.          }
  79.          catch(e:Error)
  80.          {
  81.             _hsmState(new ErrorEvent(ErrorEvent.ERROR,false,false,e.message,e.errorID));
  82.          }
  83.       }
  84.    }
  85. }
  86.